using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Ocelot.DependencyInjection;
using Ocelot.Middleware;
using Ocelot.Provider.Consul;

namespace ApiGateway
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder
                        .ConfigureAppConfiguration((hostContext, config) =>
                        {
                            config
                                .SetBasePath(hostContext.HostingEnvironment.ContentRootPath)
                                .AddOcelot("Config", hostContext.HostingEnvironment);
                        })
                        .ConfigureServices(services =>
                        {
                            services
                                .AddOcelot()
                                .AddConsul()
                                .AddConfigStoredInConsul();
                        })
                        .Configure(app =>
                        {
                            app.UseOcelot().Wait();
                        });
                        //.UseStartup<Startup>();
                });
    }
}
